package de.hfu.mdsd.mm.guimodel.android.generator;

import java.util.HashMap;

public class CounterImpl implements Counter {

	private HashMap<String, Integer> map = new HashMap<String, Integer>();

	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * de.hfu.mdsd.mm.guimodel.android.generator.Counter#getCounter(java.lang
	 * .String)
	 */
	@Override
	public Integer getCounter(String value) {
		Integer result = map.get(value);
		if (result != null) {
			return result;
		}
		map.put(value, 0);
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * de.hfu.mdsd.mm.guimodel.android.generator.Counter#incCounter(java.lang
	 * .String)
	 */
	@Override
	public void incCounter(String value) {
		Integer result = map.get(value);
		if (result != null) {
			map.remove(value);
			map.put(value, result + 1);
			return;
		}
		map.put(value, 1);
	}

	@Override
	public void resetCounter(String value) {
		Integer result = map.get(value);
		if (result != null) {
			map.remove(value);
			map.put(value, 0);
		}
	}
	
	@Override
	public void deleteCounter(String value) {
		Integer result = map.get(value);
		if (result != null) {
			map.remove(value);
		}
	}

	@Override
	public void initializeCounter(String value) {
		map.put(value, 0);		
	}
}